﻿using Bikiball.Graphic.Vextex;
using SharpDX;
using SharpDX.Toolkit.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bikiball.Graphic.Constructor
{
    public  static class MapConstructor
    {
        public static Texture3D MapTexture = null;
        public static Effect MapEffect = null;

        public static void LoadContent()
        {
            MapTexture = GraphicEngine.Content.Load<Texture3D>("map.dds");
            MapEffect = GraphicEngine.Content.Load<Effect>("Map.fxo");
        }
        public static GraphicProperty Construct(float SizeX, float SizeY, float SizeZ)
        {
            GraphicProperty gp = new GraphicProperty();
            // Creates a basic effect
           /* gp.Effect = new BasicEffect(GraphicEngine.GraphicsDevice)
            {
                VertexColorEnabled = true,
                View = Matrix.LookAtLH(new Vector3(0.0001f, -5, -5), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)(GraphicEngine.GraphicsDevice.BackBuffer).Width / (GraphicEngine.GraphicsDevice.BackBuffer).Height, 0.1f, 100.0f),
                World = Matrix.Zero
            };*/
            gp.Effect = MapEffect;

            // Creates vertices for the cube
            VertexPositionTexture3D[] vertices = new[]
                    {
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 44.0f/256.0f)), // Front
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, -1.0f), new Vector3(0.0f, 1, 44.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, -1.0f), new Vector3(1, 1, 44.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 44.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, -1.0f), new Vector3(1, 1, 44.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, -1.0f), new Vector3(1, 0.0f, 44.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f/256.0f)), // BACK
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 4.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 4.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 4.0f/256.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)), // Top
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)), // Bottom
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)), // Left
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(-1.0f, 1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)), // Right
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, -1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, -1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                        new VertexPositionTexture3D(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f)),
                    };
            gp.VertexBuffer = SharpDX.Toolkit.Graphics.Buffer.Vertex.New<VertexPositionTexture3D>(GraphicEngine.GraphicsDevice, vertices);
            gp.NumVertices = vertices.Length;
            gp.Texture = MapTexture;
            gp.VertexStride = VertexPositionTexture3D.Size;
            // Create an input layout from the vertices
            gp.InputLayout = VertexInputLayout.FromBuffer(0, (Buffer<VertexPositionTexture3D>) gp.VertexBuffer);
            return gp;
        }
    }
}
